package implementations.dm_kernel;

import interfaces.kernel.JCL_message_global_var;

import java.io.File;
import java.io.FileInputStream;

public class MessageGlobalVarImpl extends MessageImpl implements JCL_message_global_var{

	
	/**
	 * 
	 */
	private static final long serialVersionUID = -2910426405812417358L;
	private String nickName;
	private String varName;
	private byte[][] varType;
	private String[] fileNames;
	private Object[] defaultValues;
	private Object instance;
	
	public MessageGlobalVarImpl(String nickName, String varName, File[] jars,
			Object[] defaultVarValue){
		this.varName = varName;
		try{
			this.varType = new byte[jars.length][];
			this.fileNames = new String [jars.length];
			this.nickName = nickName;
			int i=0;
			for(File f: jars){
				byte[] oneF = new byte[(int)f.length()];
				new FileInputStream(f).read(oneF);
				this.varType[i] = oneF;
				this.fileNames[i] = jars[i].getName();				
				System.err.println("jar converted " + this.fileNames[i] + " size " + oneF.length);
				i++;
			}
		}catch(Exception e){
			e.printStackTrace();
		}
		this.defaultValues = defaultVarValue;
	}
	
	public MessageGlobalVarImpl(String varName, Object instance){
		this.varName = varName;
		this.instance = instance;
	}
	
	@Override
	public String getVarName() {
		return varName;
	}

	@Override
	public byte[][] getJars() {
		return varType;
	}
	
	@Override
	public String[] getJarsNames() {
		return fileNames;
	}

	@Override
	public Object[] getDefaultValues() {
		return defaultValues;
	}

	@Override
	public Object getVarInstance() {
		return instance;
	}
	
	@Override
	public String getNickName() {
		return nickName;
	}
	

}
